<template>
<div>
  <h2>&nbsp;</h2>
  <div class="container bg-gray-eee box-shadow mar-bottom-30"
       style="padding-right: 0px; padding-left: 0px; position: relative; margin-top: 120px;">

    <table rules="all" border="0" cellspacing="0" cellpadding="0"
           class="table table-hover table-striped font12 table-bordered v-align-top"
           style="table-layout:fixed;word-wrap:break-word;text-align: center">
      <tr class="firstTr" style="text-align: center;font-size:10px">
        <td width="10%"><h4>航班号</h4></td>
        <td width="25%"><h4>航班路线</h4></td>
        <td width="12%"><h4>出发时间</h4></td>
        <td width="12%"><h4>到达时间</h4></td>
        <td width="10%"><h4>座位类型</h4></td>
        <td width="15%"><h4>价格</h4></td>

      </tr>

      <tr style="text-align: center">
        <td style="white-space:nowrap;overflow:hidden;text-overflow: ellipsis;"><h3>{{flight.id}}</h3></td>
        <td>
          <h3 >{{flight.srcAirport}}------>{{flight.dstAirport}}</h3>
        </td>
        <td>
          <li class="text-right w80"><strong class="time ">{{dateFormat(flight.startTime)}}</strong></li>
          <li class="text-right w80"><strong class="time ">{{timeFormat(flight.startTime)}}</strong></li>
        </td>
        <td>
          <li class="text-right w80"><strong class="time ">{{dateFormat(flight.endTime)}}</strong></li>
          <li class="text-right w80"><strong class="time ">{{timeFormat(flight.endTime)}}</strong></li>
        </td>
        <td><h3>{{type}}</h3></td>
        <td>
          <h3 style="color: orange">￥{{price}}</h3>
        </td>
      </tr>

    </table>

  </div>
  <div class="text-center" style="margin:20px;">



   <button class="btn btn-danger btn-sm" onclick="javascript:history.back(-1)">
     返回首页</button>&nbsp;
    <button class="btn btn-danger btn-sm" @click="book">去支付</button>
  </div>
</div>
</template>

<script>
import {formatDate} from "@/common/date";

export default {
  name: "ConfirmBook",
  data(){
    return{
        flight:'',
        price:9999,
        flightId:'',
        seatType:1,
        type:1,
        result:'',
        confirm:false,
        passenger:{
          passengerId:null,
          cardId:null,
          passengerName:'',
          phone:'',
          password:'',
          avatarImg:null,
          nickName:null,
          city:null,
          email:null,
          wechat:null,
      },
    }
  },
  methods:{
    timeFormat(time){
      var date = new Date(time);
      return formatDate(date,"hh:mm");
    },
    dateFormat(day){
      var date = new Date(day);
      return formatDate(date,"MM-dd");
    },
    book(){
      if(this.confirm==true){
        alert("不能反复订票")

      }else{
        const _this = this;
        this.$axios.post('http://localhost:8181/flight/bookFlight/'+this.flightId+'/'+this.seatType+'/'+this.passenger.passengerId)
            .then((resp)=>{
              _this.result=resp.data
              if(_this.result=='success'){
                this.$message({
                  message: '订票成功',
                  type: 'success'
                });
                _this.confirm=true
              }
              else{
                alert("票卖完了")
              }
              _this.$router.replace('/IndexPage')

            })
      }



    },


  },
  created(){

    // this.$session.set('passengerSession', JSON.stringify(this.passenger));

    this.passenger=JSON.parse(sessionStorage.getItem('passenger'))
    this.flightId=this.$route.query.flightId
    this.seatType=this.$route.query.seatType
    this.type=this.$route.query.seatType
    const _this=this

    this.$axios.post('http://localhost:8181/flight/getFlight/'+_this.flightId)
      .then(function (resp){
          _this.flight=resp.data
          console.log(_this.flight)
        if(_this.seatType==2){
          _this.price=_this.flight.economicPrice
          _this.type='经济舱'
        }
        else{
          _this.price=_this.flight.advancedPrice
          _this.type='头等舱'
        }
      })
  }
}


</script>

<style scoped>

</style>
